<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Versions extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        if ($this->hasTable('versions')) return;
        $this->table('versions', ['engine' => 'Innodb'])
            ->setComment('版本记录表')
            ->setCollation(env('DATABASE.CHARSET_COLLATION'))
            ->setId('version_id')
            ->setPrimaryKey('version_id')
            ->addColumn('version_name', 'string', ['limit' => 256, 'default' => '', 'comment' => '名称'])
            ->addColumn('version_number', 'string', ['limit' => 256, 'default' => '', 'comment' => '版本号'])
            ->addColumn(Column::text('version_content')->setComment('内容'))
            ->addColumn(Column::integer('version_sort')->setUnsigned()->setDefault(0)->setComment('排序[从小到大]'))
            ->addColumn(Column::boolean('is_check')->setUnsigned()->setDefault(1)->setComment('是否启用：1：是；0：否'))
            ->addColumn(Column::boolean('is_delete')->setUnsigned()->setDefault(0)->setComment('是否删除：1：删除；0：正常'))
            ->addColumn(Column::integer('created_time')->setUnsigned()->setDefault(0)->setComment('创建时间'))
            ->addColumn(Column::integer('updated_time')->setUnsigned()->setDefault(0)->setComment('更新时间'))
            ->addIndex('is_check')
            ->addIndex('is_delete')
            ->create();
    }
}